home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / rmail / rmailsum.el.z / rmailsum.el
Encoding:
Text File  |  1998-05-21  |  38.9 KB  |  1,099 lines

  1. ;;; rmailsum.el --- make summary buffers for the mail reader
  2.  
  3. ;; Copyright (C) 1985, 1993 Free Software Foundation, Inc.
  4.  
  5. ;; Maintainer: FSF
  6. ;; Keywords: mail
  7.  
  8. ;; This file is part of XEmacs.
  9.  
  10. ;; XEmacs is free software; you can redistribute it and/or modify it
  11. ;; under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; XEmacs is distributed in the hope that it will be useful, but
  16. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. ;; General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with XEmacs; see the file COPYING.  If not, write to the 
  22. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  23. ;; Boston, MA 02111-1307, USA.
  24.  
  25. ;;; Commentary:
  26.  
  27. ;; Extended by Bob Weiner of Motorola
  28. ;;   Provided all commands from rmail-mode in rmail-summary-mode and made key
  29. ;;   bindings in both modes wholly compatible.
  30.  
  31. ;;; Code:
  32.  
  33. ;; Entry points for making a summary buffer.
  34.  
  35. (defvar rmail-summary-redo)
  36. (defvar rmail-buffer)
  37. (defvar rmail-summary-mode-map nil)
  38.  
  39. ;; Regenerate the contents of the summary
  40. ;; using the same selection criterion as last time.
  41. ;; M-x revert-buffer in a summary buffer calls this function.
  42. (defun rmail-update-summary (&rest ignore)
  43.   (apply (car rmail-summary-redo) (cdr rmail-summary-redo)))
  44.  
  45. (defun rmail-summary ()
  46.   "Display a summary of all messages, one line per message."
  47.   (interactive)
  48.   (rmail-new-summary "All" '(rmail-summary) nil))
  49.  
  50. (defun rmail-summary-by-labels (labels)
  51.   "Display a summary of all messages with one or more LABELS.
  52. LABELS should be a string containing the desired labels, separated by commas."
  53.   (interactive "sLabels to summarize by: ")
  54.   (if (string= labels "")
  55.       (setq labels (or rmail-last-multi-labels
  56.                (error "No label specified"))))
  57.   (setq rmail-last-multi-labels labels)
  58.   (rmail-new-summary (concat "labels " labels)
  59.              (list 'rmail-summary-by-labels labels)
  60.              'rmail-message-labels-p
  61.              (concat ", \\(" (mail-comma-list-regexp labels) "\\),")))
  62.  
  63. (defun rmail-summary-by-recipients (recipients &optional primary-only)
  64.   "Display a summary of all messages with the given RECIPIENTS.
  65. Normally checks the To, From and Cc fields of headers;
  66. but if PRIMARY-ONLY is non-nil (prefix arg given),
  67.  only look in the To and From fields.
  68. RECIPIENTS is a string of regexps separated by commas."
  69.   (interactive "sRecipients to summarize by: \nP")
  70.   (rmail-new-summary
  71.    (concat "recipients " recipients)
  72.    (list 'rmail-summary-by-recipients recipients primary-only)
  73.    'rmail-message-recipients-p
  74.    (mail-comma-list-regexp recipients) primary-only))
  75.  
  76. (defun rmail-summary-by-regexp (regexp)
  77.   "Display a summary of all messages according to regexp REGEXP.
  78. If the regular expression is found in the header of the message
  79. \(including in the date and other lines, as well as the subject line),
  80. Emacs will list the header line in the RMAIL-summary."
  81.   (interactive "sRegexp to summarize by: ")
  82.   (if (string= regexp "")
  83.       (setq regexp (or rmail-last-regexp
  84.              (error "No regexp specified."))))
  85.   (setq rmail-last-regexp regexp)
  86.   (rmail-new-summary (concat "regexp " regexp)
  87.              (list 'rmail-summary-by-regexp regexp)
  88.              'rmail-message-regexp-p
  89.                      regexp))
  90.  
  91. ;; rmail-summary-by-topic
  92. ;; 1989 R.A. Schnitzler
  93.  
  94. (defun rmail-summary-by-topic (subject &optional whole-message)
  95.   "Display a summary of all messages with the given SUBJECT.
  96. Normally checks the Subject field of headers;
  97. but if WHOLE-MESSAGE is non-nil (prefix arg given), 
  98.  look in the whole message.
  99. SUBJECT is a string of regexps separated by commas."
  100.   (interactive "sTopics to summarize by: \nP")
  101.   (rmail-new-summary
  102.    (concat "about " subject)
  103.    (list 'rmail-summary-by-topic subject whole-message)
  104.    'rmail-message-subject-p
  105.    (mail-comma-list-regexp subject) whole-message))
  106.  
  107. (defun rmail-message-subject-p (msg subject &optional whole-message)
  108.   (save-restriction
  109.     (goto-char (rmail-msgbeg msg))
  110.     (search-forward "\n*** EOOH ***\n")
  111.     (narrow-to-region
  112.      (point)
  113.      (progn (search-forward (if whole-message "\^_" "\n\n")) (point)))
  114.     (goto-char (point-min))
  115.     (if whole-message (re-search-forward subject nil t)
  116.       (string-match subject (or (mail-fetch-field "Subject") "")) )))
  117.  
  118. (defun rmail-summary-by-senders (senders)
  119.   "Display a summary of all messages with the given SENDERS.
  120. SENDERS is a string of names separated by commas."
  121.   (interactive "sSenders to summarize by: ")
  122.   (rmail-new-summary
  123.    (concat "senders " senders)
  124.    'rmail-message-senders-p
  125.    (mail-comma-list-regexp senders)))
  126.  
  127. (defun rmail-message-senders-p (msg senders)
  128.   (save-restriction
  129.     (goto-char (rmail-msgbeg msg))
  130.     (search-forward "\n*** EOOH ***\n")
  131.     (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
  132.     (string-match senders (or (mail-fetch-field "From") ""))))
  133.  
  134. ;; General making of a summary buffer.
  135.  
  136. (defvar rmail-summary-symbol-number 0)
  137.  
  138. (defun rmail-new-summary (description redo-form function &rest args)
  139.   "Create a summary of selected messages.
  140. DESCRIPTION makes part of the mode line of the summary buffer.
  141. For each message, FUNCTION is applied to the message number and ARGS...
  142. and if the result is non-nil, that message is included.
  143. nil for FUNCTION means all messages."
  144.   (if (eq major-mode 'mime/viewer-mode)
  145.       (let ((buf mime::preview/article-buffer)
  146.         (pbuf (current-buffer))
  147.         )
  148.     (switch-to-buffer buf)
  149.     (bury-buffer pbuf)
  150.     ))
  151.   (message "Computing summary lines...")
  152.   (let (sumbuf mesg was-in-summary)
  153.     (save-excursion
  154.       ;; Go to the Rmail buffer.
  155.       (if (eq major-mode 'rmail-summary-mode)
  156.       (progn
  157.         (setq was-in-summary t)
  158.         (set-buffer rmail-buffer)))
  159.       ;; Find its summary buffer, or make one.
  160.       (setq sumbuf
  161.         (if (and rmail-summary-buffer
  162.              (buffer-name rmail-summary-buffer))
  163.         rmail-summary-buffer
  164.           (generate-new-buffer (concat (buffer-name) "-summary"))))
  165.       (setq mesg rmail-current-message)
  166.       ;; Filter the messages; make or get their summary lines.
  167.       (let ((summary-msgs ())
  168.         (new-summary-line-count 0))
  169.     (let ((msgnum 1)
  170.           (buffer-read-only nil))
  171.       (save-restriction
  172.         (save-excursion
  173.           (widen)
  174.           (goto-char (point-min))
  175.           (while (>= rmail-total-messages msgnum)
  176.         (if (or (null function)
  177.             (apply function (cons msgnum args)))
  178.             (setq summary-msgs
  179.               (cons (cons msgnum (rmail-make-summary-line msgnum))
  180.                 summary-msgs)))
  181.         (setq msgnum (1+ msgnum)))
  182.           (setq summary-msgs (nreverse summary-msgs)))))
  183.     ;; Temporarily, while summary buffer is unfinished,
  184.     ;; we "don't have" a summary.
  185.     (setq rmail-summary-buffer nil)
  186.     (save-excursion
  187.       (let ((rbuf (current-buffer))
  188.         (total rmail-total-messages))
  189.         (set-buffer sumbuf)
  190.         ;; Set up the summary buffer's contents.
  191.         (let ((buffer-read-only nil))
  192.           (erase-buffer)
  193.           (while summary-msgs
  194.         (princ (cdr (car summary-msgs)) sumbuf)
  195.         (setq summary-msgs (cdr summary-msgs)))
  196.           (goto-char (point-min)))
  197.         ;; Set up the rest of its state and local variables.
  198.         (setq buffer-read-only t)
  199.         (rmail-summary-mode)
  200.         (make-local-variable 'minor-mode-alist)
  201.         (setq minor-mode-alist (list '(t (concat ": " description))))
  202.         (setq rmail-buffer rbuf
  203.           rmail-summary-redo redo-form
  204.           rmail-total-messages total))))
  205.       (setq rmail-summary-buffer sumbuf))
  206.     ;; Now display the summary buffer and go to the right place in it.
  207.     (or was-in-summary
  208.     (pop-to-buffer sumbuf))
  209.     (rmail-summary-goto-msg mesg t t)
  210.     (message "Computing summary lines...done")))
  211.  
  212. ;; Low levels of generating a summary.
  213.  
  214. (defun rmail-make-summary-line (msg)
  215.   (let ((line (or (aref rmail-summary-vector (1- msg))
  216.           (progn
  217.             (setq new-summary-line-count
  218.               (1+ new-summary-line-count))
  219.             (if (zerop (% new-summary-line-count 10))
  220.             (message "Computing summary lines...%d"
  221.                  new-summary-line-count))
  222.             (rmail-make-summary-line-1 msg)))))
  223.     ;; Fix up the part of the summary that says "deleted" or "unseen".
  224.     (aset line 4
  225.       (if (rmail-message-deleted-p msg) ?\D
  226.         (if (= ?0 (char-after (+ 3 (rmail-msgbeg msg))))
  227.         ?\- ?\ )))
  228.     line))
  229.  
  230. (defun rmail-make-summary-line-1 (msg)
  231.   (goto-char (rmail-msgbeg msg))
  232.   (let* (;;(lim (save-excursion (forward-line 2) (point)))
  233.      pos
  234.      (labels
  235.       (progn
  236.         (forward-char 3)
  237.         (concat
  238. ;         (if (save-excursion (re-search-forward ",answered," lim t))
  239. ;         "*" "")
  240. ;         (if (save-excursion (re-search-forward ",filed," lim t))
  241. ;         "!" "")
  242.          (if (progn (search-forward ",,") (eolp))
  243.          ""
  244.            (concat "{"
  245.                (buffer-substring (point)
  246.                      (progn (end-of-line) (point)))
  247.                "} ")))))
  248.      (line
  249.       (progn
  250.         (forward-line 1)
  251.         (if (looking-at "Summary-line: ")
  252.         (progn
  253.           (goto-char (match-end 0))
  254.           (progn ;;setq line      -jwz
  255.             (buffer-substring (point)
  256.                       (progn (forward-line 1) (point)))))))))
  257.     ;; Obsolete status lines lacking a # should be flushed.
  258.     (and line
  259.      (not (string-match "#" line))
  260.      (progn
  261.        (delete-region (point)
  262.               (progn (forward-line -1) (point)))
  263.        (setq line nil)))
  264.     ;; If we didn't get a valid status line from the message,
  265.     ;; make a new one and put it in the message.
  266.     (or line
  267.     (let* ((case-fold-search t)
  268.            (next (rmail-msgend msg))
  269.            (beg (if (progn (goto-char (rmail-msgbeg msg))
  270.                    (search-forward "\n*** EOOH ***\n" next t))
  271.             (point)
  272.               (forward-line 1)
  273.               (point)))
  274.            (end (progn (search-forward "\n\n" nil t) (point))))
  275.       (save-restriction
  276.         (narrow-to-region beg end)
  277.         (goto-char beg)
  278.         (setq line (rmail-make-basic-summary-line)))
  279.       (goto-char (rmail-msgbeg msg))
  280.       (forward-line 2)
  281.       (insert "Summary-line: " line)))
  282.     (setq pos (string-match "#" line))
  283.     (aset rmail-summary-vector (1- msg)
  284.       (concat (format "%4d  " msg)
  285.           (substring line 0 pos)
  286.           labels
  287.           (substring line (1+ pos))))))
  288.  
  289. (defun rmail-make-basic-summary-line ()
  290.   (goto-char (point-min))
  291.   (concat (save-excursion
  292.         (if (not (re-search-forward "^Date:" nil t))
  293.         "      "
  294.           (cond ((re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
  295.               (save-excursion (end-of-line) (point)) t)
  296.              (format "%2d-%3s"
  297.                  (string-to-int (buffer-substring
  298.                          (match-beginning 2)
  299.                          (match-end 2)))
  300.                  (buffer-substring
  301.                   (match-beginning 4) (match-end 4))))
  302.             ((re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
  303.               (save-excursion (end-of-line) (point)) t)
  304.              (format "%2d-%3s"
  305.                  (string-to-int (buffer-substring
  306.                          (match-beginning 4)
  307.                          (match-end 4)))
  308.                  (buffer-substring
  309.                   (match-beginning 2) (match-end 2))))
  310.             (t "??????"))))
  311.       "  "
  312.       (save-excursion
  313.         (if (not (re-search-forward "^From:[ \t]*" nil t))
  314.         "                         "
  315.           (let* ((from (mail-strip-quoted-names
  316.                 (buffer-substring
  317.                  (1- (point))
  318.                  (progn (end-of-line)
  319.                     (skip-chars-backward " \t")
  320.                     (point)))))
  321.              len mch lo)
  322.         (if (string-match (concat "^"
  323.                       (regexp-quote (user-login-name))
  324.                       "\\($\\|@\\)")
  325.                   from)
  326.             (save-excursion
  327.               (goto-char (point-min))
  328.               (if (not (re-search-forward "^To:[ \t]*" nil t))
  329.               nil
  330.             (setq from
  331.                   (concat "to: "
  332.                       (mail-strip-quoted-names
  333.                        (buffer-substring
  334.                     (point)
  335.                     (progn (end-of-line)
  336.                            (skip-chars-backward " \t")
  337.                            (point)))))))))
  338.         (setq len (length from))
  339.         (setq mch (string-match "[@%]" from))
  340.         (format "%25s"
  341.             (if (or (not mch) (<= len 25))
  342.                 (substring from (max 0 (- len 25)))
  343.               (substring from
  344.                      (setq lo (cond ((< (- mch 9) 0) 0)
  345.                             ((< len (+ mch 16))
  346.                              (- len 25))
  347.                             (t (- mch 9))))
  348.                      (min len (+ lo 25))))))))
  349.       "  #"
  350.       (if (re-search-forward "^Subject:" nil t)
  351.           (progn (skip-chars-forward " \t")
  352.              (buffer-substring (point)
  353.                        (progn (end-of-line)
  354.                           (point))))
  355.         (re-search-forward "[\n][\n]+" nil t)
  356.         (buffer-substring (point) (progn (end-of-line) (point))))
  357.       "\n"))
  358.  
  359. ;; Simple motion in a summary buffer.
  360.  
  361. (defun rmail-summary-next-all (&optional number)
  362.   (interactive "p")
  363.   (forward-line (if number number 1))
  364.   (display-buffer rmail-buffer))
  365.  
  366. (defun rmail-summary-previous-all (&optional number)
  367.   (interactive "p")
  368.   (forward-line (- (if number number 1)))
  369.   (display-buffer rmail-buffer))
  370.  
  371. (defun rmail-summary-next-msg (&optional number)
  372.   "Display next non-deleted msg from rmail file.
  373. With optional prefix argument NUMBER, moves forward this number of non-deleted
  374. messages, or backward if NUMBER is negative."
  375.   (interactive "p")
  376.   (forward-line 0)
  377.   (and (> number 0) (end-of-line))
  378.   (let ((count (if (< number 0) (- number) number))
  379.     (search (if (> number 0) 're-search-forward 're-search-backward))
  380.     (non-del-msg-found nil))
  381.     (while (and (> count 0) (setq non-del-msg-found
  382.                   (or (funcall search "^....[^D]" nil t)
  383.                       non-del-msg-found)))
  384.       (setq count (1- count))))
  385.   (beginning-of-line)
  386.   (display-buffer rmail-buffer))
  387.  
  388. (defun rmail-summary-previous-msg (&optional number)
  389.   (interactive "p")
  390.   (rmail-summary-next-msg (- (if number number 1))))
  391.  
  392. (defun rmail-summary-next-labeled-message (n labels)
  393.   "Show next message with LABEL.  Defaults to last labels used.
  394. With prefix argument N moves forward N messages with these labels."
  395.   (interactive "p\nsMove to next msg with labels: ")
  396.   (save-excursion
  397.     (set-buffer rmail-buffer)
  398.     (rmail-next-labeled-message n labels)))
  399.  
  400. (defun rmail-summary-previous-labeled-message (n labels)
  401.   "Show previous message with LABEL.  Defaults to last labels used.
  402. With prefix argument N moves backward N messages with these labels."
  403.   (interactive "p\nsMove to previous msg with labels: ")
  404.   (save-excursion
  405.     (set-buffer rmail-buffer)
  406.     (rmail-previous-labeled-message n labels)))
  407.  
  408. ;; Delete and undelete summary commands.
  409.  
  410. (defun rmail-summary-delete-forward (&optional backward)
  411.   "Delete this message and move to next nondeleted one.
  412. Deleted messages stay in the file until the \\[rmail-expunge] command is given.
  413. With prefix argument, delete and move backward."
  414.   (interactive "P")
  415.   (progn ;;let (end) ;jwz
  416.     (rmail-summary-goto-msg)
  417.     (pop-to-buffer rmail-buffer)
  418.     (rmail-delete-forward backward)
  419.     (pop-to-buffer rmail-summary-buffer)))
  420.  
  421. (defun rmail-summary-delete-backward ()
  422.   "Delete this message and move to previous nondeleted one.
  423. Deleted messages stay in the file until the \\[rmail-expunge] command is given."
  424.   (interactive)
  425.   (rmail-summary-delete-forward t))
  426.  
  427. (defun rmail-summary-mark-deleted (&optional n undel)
  428.   (and n (rmail-summary-goto-msg n t t))
  429.   (or (eobp)
  430.       (let ((buffer-read-only nil))
  431.     (skip-chars-forward " ")
  432.     (skip-chars-forward "[0-9]")
  433.     (if undel
  434.         (if (looking-at "D")
  435.         (progn (delete-char 1) (insert " ")))
  436.       (delete-char 1)
  437.       (insert "D"))))
  438.   (beginning-of-line))
  439.  
  440. (defun rmail-summary-mark-undeleted (n)
  441.   (rmail-summary-mark-deleted n t))
  442.  
  443. (defun rmail-summary-deleted-p (&optional n)
  444.   (save-excursion
  445.     (and n (rmail-summary-goto-msg n nil t))
  446.     (skip-chars-forward " ")
  447.     (skip-chars-forward "[0-9]")
  448.     (looking-at "D")))
  449.  
  450. (defun rmail-summary-undelete (&optional arg)
  451.   "Undelete current message.
  452. Optional prefix ARG means undelete ARG previous messages."
  453.   (interactive "p")
  454.   (if (/= arg 1)
  455.       (rmail-summary-undelete-many arg)
  456.     (let ((buffer-read-only nil))
  457.       (end-of-line)
  458.       (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t)
  459.          (replace-match "\\1 ")
  460.          (rmail-summary-goto-msg)
  461.          (pop-to-buffer rmail-buffer)
  462.          (and (rmail-message-deleted-p rmail-current-message)
  463.           (rmail-undelete-previous-message))
  464.          (pop-to-buffer rmail-summary-buffer))))))
  465.  
  466. (defun rmail-summary-undelete-many (&optional n)
  467.   "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
  468.   (interactive "P")
  469.   (save-excursion
  470.     (set-buffer rmail-buffer)
  471.     (let* ((init-msg (if n rmail-current-message rmail-total-messages))
  472.        (rmail-current-message init-msg)
  473.        (n (or n rmail-total-messages))
  474.        (msgs-undeled 0))
  475.       (while (and (> rmail-current-message 0)
  476.           (< msgs-undeled n))
  477.     (if (rmail-message-deleted-p rmail-current-message)
  478.         (progn (rmail-set-attribute "deleted" nil)
  479.            (setq msgs-undeled (1+ msgs-undeled))))
  480.     (setq rmail-current-message (1- rmail-current-message)))
  481.       (set-buffer rmail-summary-buffer)
  482.       (setq rmail-current-message init-msg msgs-undeled 0)
  483.       (while (and (> rmail-current-message 0)
  484.           (< msgs-undeled n))
  485.     (if (rmail-summary-deleted-p rmail-current-message)
  486.         (progn (rmail-summary-mark-undeleted rmail-current-message)
  487.            (setq msgs-undeled (1+ msgs-undeled))))
  488.     (setq rmail-current-message (1- rmail-current-message))))
  489.     (rmail-summary-goto-msg)))
  490.  
  491. ;; Rmail Summary mode is suitable only for specially formatted data.
  492. (put 'rmail-summary-mode 'mode-class 'special)
  493.  
  494. (defun rmail-summary-mode ()
  495.   "Rmail Summary Mode is invoked from Rmail Mode by using \\<rmail-mode-map>\\[rmail-summary].
  496. As commands are issued in the summary buffer, they are applied to the
  497. corresponding mail messages in the rmail buffer.
  498.  
  499. All normal editing commands are turned off.
  500. Instead, nearly all the Rmail mode commands are available,
  501. though many of them move only among the messages in the summary.
  502.  
  503. These additional commands exist:
  504.  
  505. \\[rmail-summary-undelete-many]    Undelete all or prefix arg deleted messages.
  506. \\[rmail-summary-wipe] Delete the summary and go to the Rmail buffer.
  507.  
  508. Commands for sorting the summary:
  509.  
  510. \\[rmail-summary-sort-by-date] Sort by date.
  511. \\[rmail-summary-sort-by-subject] Sort by subject.
  512. \\[rmail-summary-sort-by-author] Sort by author.
  513. \\[rmail-summary-sort-by-recipient] Sort by recipient.
  514. \\[rmail-summary-sort-by-correspondent] Sort by correspondent.
  515. \\[rmail-summary-sort-by-lines] Sort by lines."
  516.   (interactive)
  517.   (kill-all-local-variables)
  518.   (setq major-mode 'rmail-summary-mode)
  519.   (setq mode-name "RMAIL Summary")
  520.   (use-local-map rmail-summary-mode-map)
  521.   (setq truncate-lines t)
  522.   (setq buffer-read-only t)
  523.   (set-syntax-table text-mode-syntax-table)
  524.   (make-local-variable 'rmail-buffer)
  525.   (make-local-variable 'rmail-total-messages)
  526.   (make-local-variable 'rmail-current-message)
  527.   (setq rmail-current-message nil)
  528.   (make-local-variable 'rmail-summary-redo)
  529.   (setq rmail-summary-redo nil)
  530.   (make-local-variable 'revert-buffer-function)
  531.   (setq revert-buffer-function 'rmail-update-summary)
  532.   (make-local-hook 'post-command-hook)
  533.   (add-hook 'post-command-hook 'rmail-summary-rmail-update nil t)
  534.   (run-hooks 'rmail-summary-mode-hook))
  535.  
  536. ;; Show in Rmail the message described by the summary line that point is on,
  537. ;; but only if the Rmail buffer is already visible.
  538. ;; This is a post-command-hook in summary buffers.
  539. (defun rmail-summary-rmail-update ()
  540.   (if (get-buffer-window rmail-buffer)
  541.       (let (buffer-read-only)
  542.     (save-excursion
  543.       (beginning-of-line)
  544.       (skip-chars-forward " ")
  545.       (let ((beg (point))
  546.         msg-num
  547.         ;;(buf rmail-buffer)
  548.         )
  549.         (skip-chars-forward "0-9")
  550.         (setq msg-num (string-to-int (buffer-substring beg (point))))
  551.         (or (eq rmail-current-message msg-num)
  552.         (let (;;go-where
  553.               window (owin (selected-window)))
  554.           (setq rmail-current-message msg-num)
  555.           (if (= (following-char) ?-)
  556.               (progn
  557.             (delete-char 1)
  558.             (insert " ")))
  559.           (setq window (display-buffer rmail-buffer))
  560.           ;; Using save-window-excursion caused the new value
  561.           ;; of point to get lost.
  562.           (unwind-protect
  563.               (progn
  564.             (select-window window)
  565.             (rmail-show-message msg-num))
  566.             (select-window owin)))))))))
  567.  
  568. (if rmail-summary-mode-map
  569.     nil
  570.   (setq rmail-summary-mode-map (make-keymap))
  571.   (suppress-keymap rmail-summary-mode-map)
  572.   (define-key rmail-summary-mode-map "a"      'rmail-summary-add-label)
  573.   (define-key rmail-summary-mode-map "c"      'rmail-summary-continue)
  574.   (define-key rmail-summary-mode-map "d"      'rmail-summary-delete-forward)
  575.   (define-key rmail-summary-mode-map "\C-d"   'rmail-summary-delete-backward)
  576.   (define-key rmail-summary-mode-map "e"      'rmail-summary-edit-current-message)
  577.   (define-key rmail-summary-mode-map "f"      'rmail-summary-forward)
  578.   (define-key rmail-summary-mode-map "g"      'rmail-summary-get-new-mail)
  579.   (define-key rmail-summary-mode-map "h"      'rmail-summary)
  580.   (define-key rmail-summary-mode-map "i"      'rmail-summary-input)
  581.   (define-key rmail-summary-mode-map "j"      'rmail-summary-goto-msg)
  582.   (define-key rmail-summary-mode-map "k"      'rmail-summary-kill-label)
  583.   (define-key rmail-summary-mode-map "l"      'rmail-summary-by-labels)
  584.   (define-key rmail-summary-mode-map "\e\C-h" 'rmail-summary)
  585.   (define-key rmail-summary-mode-map "\e\C-l" 'rmail-summary-by-labels)
  586.   (define-key rmail-summary-mode-map "\e\C-r" 'rmail-summary-by-recipients)
  587.   (define-key rmail-summary-mode-map "\e\C-s" 'rmail-summary-by-regexp)
  588.   (define-key rmail-summary-mode-map "\e\C-t" 'rmail-summary-by-topic)
  589.   (define-key rmail-summary-mode-map "m"      'rmail-summary-mail)
  590.   (define-key rmail-summary-mode-map "\M-m"   'rmail-summary-retry-failure)
  591.   (define-key rmail-summary-mode-map "n"      'rmail-summary-next-msg)
  592.   (define-key rmail-summary-mode-map "\en"    'rmail-summary-next-all)
  593.   (define-key rmail-summary-mode-map "\e\C-n" 'rmail-summary-next-labeled-message)
  594.   (define-key rmail-summary-mode-map "o"      'rmail-summary-output-to-rmail-file)
  595.   (define-key rmail-summary-mode-map "\C-o"   'rmail-summary-output)
  596.   (define-key rmail-summary-mode-map "p"      'rmail-summary-previous-msg)
  597.   (define-key rmail-summary-mode-map "\ep"    'rmail-summary-previous-all)
  598.   (define-key rmail-summary-mode-map "\e\C-p" 'rmail-summary-previous-labeled-message)
  599.   (define-key rmail-summary-mode-map "q"      'rmail-summary-quit)
  600.   (define-key rmail-summary-mode-map "r"      'rmail-summary-reply)
  601.   (define-key rmail-summary-mode-map "s"      'rmail-summary-expunge-and-save)
  602.   (define-key rmail-summary-mode-map "\es"    'rmail-summary-search)
  603.   (define-key rmail-summary-mode-map "t"      'rmail-summary-toggle-header)
  604.   (define-key rmail-summary-mode-map "u"      'rmail-summary-undelete)
  605.   (define-key rmail-summary-mode-map "\M-u"   'rmail-summary-undelete-many)
  606.   (define-key rmail-summary-mode-map "w"      'rmail-summary-wipe)
  607.   (define-key rmail-summary-mode-map "x"      'rmail-summary-expunge)
  608.   (define-key rmail-summary-mode-map "."      'rmail-summary-beginning-of-message)
  609.   (define-key rmail-summary-mode-map "<"      'rmail-summary-first-message)
  610.   (define-key rmail-summary-mode-map ">"      'rmail-summary-last-message)
  611.   (define-key rmail-summary-mode-map " "      'rmail-summary-scroll-msg-up)
  612.   (define-key rmail-summary-mode-map "\177"   'rmail-summary-scroll-msg-down)
  613.   (define-key rmail-summary-mode-map "?"      'describe-mode)
  614.   (define-key rmail-summary-mode-map "\C-c\C-s\C-d"
  615.     'rmail-summary-sort-by-date)
  616.   (define-key rmail-summary-mode-map "\C-c\C-s\C-s"
  617.     'rmail-summary-sort-by-subject)
  618.   (define-key rmail-summary-mode-map "\C-c\C-s\C-a"
  619.     'rmail-summary-sort-by-author)
  620.   (define-key rmail-summary-mode-map "\C-c\C-s\C-r"
  621.     'rmail-summary-sort-by-recipient)
  622.   (define-key rmail-summary-mode-map "\C-c\C-s\C-c"
  623.     'rmail-summary-sort-by-correspondent)
  624.   (define-key rmail-summary-mode-map "\C-c\C-s\C-l"
  625.     'rmail-summary-sort-by-lines)
  626.   )
  627.  
  628. ;;; Menu bar bindings.
  629. ;
  630. ;(define-key rmail-summary-mode-map [menu-bar] (make-sparse-keymap))
  631. ;
  632. ;(define-key rmail-summary-mode-map [menu-bar classify]
  633. ;  (cons "Classify" (make-sparse-keymap "Classify")))
  634. ;
  635. ;(define-key rmail-summary-mode-map [menu-bar classify output-inbox]
  636. ;  '("Output (inbox)" . rmail-summary-output))
  637. ;
  638. ;(define-key rmail-summary-mode-map [menu-bar classify output]
  639. ;  '("Output (Rmail)" . rmail-summary-output-to-rmail-file))
  640. ;
  641. ;(define-key rmail-summary-mode-map [menu-bar classify kill-label]
  642. ;  '("Kill Label" . rmail-summary-kill-label))
  643. ;
  644. ;(define-key rmail-summary-mode-map [menu-bar classify add-label]
  645. ;  '("Add Label" . rmail-summary-add-label))
  646. ;
  647. ;(define-key rmail-summary-mode-map [menu-bar summary]
  648. ;  (cons "Summary" (make-sparse-keymap "Summary")))
  649. ;
  650. ;(define-key rmail-summary-mode-map [menu-bar summary labels]
  651. ;  '("By Labels" . rmail-summary-by-labels))
  652. ;
  653. ;(define-key rmail-summary-mode-map [menu-bar summary recipients]
  654. ;  '("By Recipients" . rmail-summary-by-recipients))
  655. ;
  656. ;(define-key rmail-summary-mode-map [menu-bar summary topic]
  657. ;  '("By Topic" . rmail-summary-by-topic))
  658. ;
  659. ;(define-key rmail-summary-mode-map [menu-bar summary regexp]
  660. ;  '("By Regexp" . rmail-summary-by-regexp))
  661. ;
  662. ;(define-key rmail-summary-mode-map [menu-bar summary all]
  663. ;  '("All" . rmail-summary))
  664. ;
  665. ;(define-key rmail-summary-mode-map [menu-bar mail]
  666. ;  (cons "Mail" (make-sparse-keymap "Mail")))
  667. ;
  668. ;(define-key rmail-summary-mode-map [menu-bar mail continue]
  669. ;  '("Continue" . rmail-summary-continue))
  670. ;
  671. ;(define-key rmail-summary-mode-map [menu-bar mail forward]
  672. ;  '("Forward" . rmail-summary-forward))
  673. ;
  674. ;(define-key rmail-summary-mode-map [menu-bar mail retry]
  675. ;  '("Retry" . rmail-summary-retry-failure))
  676. ;
  677. ;(define-key rmail-summary-mode-map [menu-bar mail reply]
  678. ;  '("Reply" . rmail-summary-reply))
  679. ;
  680. ;(define-key rmail-summary-mode-map [menu-bar mail mail]
  681. ;  '("Mail" . rmail-summary-mail))
  682. ;
  683. ;(define-key rmail-summary-mode-map [menu-bar delete]
  684. ;  (cons "Delete" (make-sparse-keymap "Delete")))
  685. ;
  686. ;(define-key rmail-summary-mode-map [menu-bar delete expunge/save]
  687. ;  '("Expunge/Save" . rmail-summary-expunge-and-save))
  688. ;
  689. ;(define-key rmail-summary-mode-map [menu-bar delete expunge]
  690. ;  '("Expunge" . rmail-summary-expunge))
  691. ;
  692. ;(define-key rmail-summary-mode-map [menu-bar delete undelete]
  693. ;  '("Undelete" . rmail-summary-undelete))
  694. ;
  695. ;(define-key rmail-summary-mode-map [menu-bar delete delete]
  696. ;  '("Delete" . rmail-summary-delete-forward))
  697. ;
  698. ;(define-key rmail-summary-mode-map [menu-bar move]
  699. ;  (cons "Move" (make-sparse-keymap "Move")))
  700. ;
  701. ;(define-key rmail-summary-mode-map [menu-bar move search-back]
  702. ;  '("Search Back" . rmail-summary-search-backward))
  703. ;
  704. ;(define-key rmail-summary-mode-map [menu-bar move search]
  705. ;  '("Search" . rmail-summary-search))
  706. ;
  707. ;(define-key rmail-summary-mode-map [menu-bar move previous]
  708. ;  '("Previous Nondeleted" . rmail-summary-previous-msg))
  709. ;
  710. ;(define-key rmail-summary-mode-map [menu-bar move next]
  711. ;  '("Next Nondeleted" . rmail-summary-next-msg))
  712. ;
  713. ;(define-key rmail-summary-mode-map [menu-bar move last]
  714. ;  '("Last" . rmail-summary-last-message))
  715. ;
  716. ;(define-key rmail-summary-mode-map [menu-bar move first]
  717. ;  '("First" . rmail-summary-first-message))
  718. ;
  719. ;(define-key rmail-summary-mode-map [menu-bar move previous]
  720. ;  '("Previous" . rmail-summary-previous-all))
  721. ;
  722. ;(define-key rmail-summary-mode-map [menu-bar move next]
  723. ;  '("Next" . rmail-summary-next-all))
  724.  
  725. (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail)
  726.   (interactive "P")
  727.   (if (consp n) (setq n (prefix-numeric-value n)))
  728.   (if (eobp) (forward-line -1))
  729.   (beginning-of-line)
  730.   (let ((buf rmail-buffer)
  731.     (cur (point))
  732.     (curmsg (string-to-int
  733.          (buffer-substring (point)
  734.                    (min (point-max) (+ 5 (point)))))))
  735.     (if (not n)
  736.     (setq n curmsg)
  737.       (if (< n 1)
  738.       (progn (message "No preceding message")
  739.          (setq n 1)))
  740.       (if (> n rmail-total-messages)
  741.       (progn (message "No following message")
  742.          (goto-char (point-max))
  743.          (rmail-summary-goto-msg)))
  744.       (goto-char (point-min))
  745.       (if (not (re-search-forward (concat "^ *" (int-to-string n)) nil t))
  746.       (progn (or nowarn (message "Message %d not found" n))
  747.          (setq n curmsg)
  748.          (goto-char cur))))
  749.     (beginning-of-line)
  750.     (skip-chars-forward " ")
  751.     (skip-chars-forward "0-9")
  752.     (save-excursion (if (= (following-char) ?-)
  753.             (let ((buffer-read-only nil))
  754.               (delete-char 1)
  755.               (insert " "))))
  756.     (beginning-of-line)
  757.     (if skip-rmail
  758.     nil
  759.       (pop-to-buffer buf)
  760.       (rmail-show-message n)
  761.       (pop-to-buffer rmail-summary-buffer))))
  762.  
  763. (defun rmail-summary-scroll-msg-up (&optional dist)
  764.   "Scroll other window forward."
  765.   (interactive "P")
  766.   (scroll-other-window dist))
  767.  
  768. (defun rmail-summary-scroll-msg-down (&optional dist)
  769.   "Scroll other window backward."
  770.   (interactive "P")
  771.   (scroll-other-window
  772.    (cond ((eq dist '-) nil)
  773.      ((null dist) '-)
  774.      (t (- (prefix-numeric-value dist))))))
  775.  
  776. (defun rmail-summary-beginning-of-message ()
  777.   "Show current message from the beginning."
  778.   (interactive)
  779.   (pop-to-buffer rmail-buffer)
  780.   (beginning-of-buffer)
  781.   (pop-to-buffer rmail-summary-buffer))
  782.  
  783. (defun rmail-summary-quit ()
  784.   "Quit out of Rmail and Rmail summary."
  785.   (interactive)
  786.   (rmail-summary-wipe)
  787.   (rmail-quit))
  788.  
  789. (defun rmail-summary-wipe ()
  790.   "Kill and wipe away Rmail summary, remaining within Rmail."
  791.   (interactive)
  792.   (save-excursion (set-buffer rmail-buffer) (setq rmail-summary-buffer nil))
  793.   (let ((local-rmail-buffer rmail-buffer))
  794.     (kill-buffer (current-buffer))
  795.     ;; Delete window if not only one.
  796.     (if (not (eq (selected-window) (next-window nil 'no-minibuf)))
  797.     (delete-window))
  798.     ;; Switch windows to the rmail buffer, or switch to it in this window.
  799.     (pop-to-buffer local-rmail-buffer)))
  800.  
  801. (defun rmail-summary-expunge ()
  802.   "Actually erase all deleted messages and recompute summary headers."
  803.   (interactive)
  804.   (save-excursion
  805.     (set-buffer rmail-buffer)
  806.     (rmail-only-expunge))
  807.   (rmail-update-summary))
  808.  
  809. (defun rmail-summary-expunge-and-save ()
  810.   "Expunge and save RMAIL file."
  811.   (interactive)
  812.   (save-excursion
  813.     (set-buffer rmail-buffer)
  814.     (rmail-only-expunge))
  815.   (rmail-update-summary)
  816.   (save-excursion
  817.     (set-buffer rmail-buffer)
  818.     (save-buffer)))
  819.  
  820. (defun rmail-summary-get-new-mail ()
  821.   "Get new mail and recompute summary headers."
  822.   (interactive)
  823.   (let (msg)
  824.     (save-excursion
  825.       (set-buffer rmail-buffer)
  826.       (rmail-get-new-mail)
  827.       ;; Get the proper new message number.
  828.       (setq msg rmail-current-message))
  829.     ;; Make sure that message is displayed.
  830.     (rmail-summary-goto-msg msg)))
  831.  
  832. (defun rmail-summary-input (filename)
  833.   "Run Rmail on file FILENAME."
  834.   (interactive "FRun rmail on RMAIL file: ")
  835.   ;; We switch windows here, then display the other Rmail file there.
  836.   (pop-to-buffer rmail-buffer)
  837.   (rmail filename))
  838.  
  839. (defun rmail-summary-first-message ()
  840.   "Show first message in Rmail file from summary buffer."
  841.   (interactive)
  842.   (beginning-of-buffer))
  843.  
  844. (defun rmail-summary-last-message ()
  845.   "Show last message in Rmail file from summary buffer."
  846.   (interactive)
  847.   (end-of-buffer)
  848.   (forward-line -1))
  849.  
  850. (defvar rmail-summary-edit-map nil)
  851. (if rmail-summary-edit-map
  852.     nil
  853.   (setq rmail-summary-edit-map (make-sparse-keymap))
  854.   (set-keymap-parent rmail-summary-edit-map text-mode-map)
  855.   (set-keymap-name rmail-summary-edit-map 'rmail-summary-edit-map)
  856.   (define-key rmail-summary-edit-map "\C-c\C-c" 'rmail-cease-edit)
  857.   (define-key rmail-summary-edit-map "\C-c\C-]" 'rmail-abort-edit))
  858.  
  859. (defun rmail-summary-edit-current-message ()
  860.   "Edit the contents of this message."
  861.   (interactive)
  862.   (pop-to-buffer rmail-buffer)
  863.   (rmail-edit-current-message)
  864.   (use-local-map rmail-summary-edit-map))
  865.  
  866. (defun rmail-summary-cease-edit ()
  867.   "Finish editing message, then go back to Rmail summary buffer."
  868.   (interactive)
  869.   (rmail-cease-edit)
  870.   (pop-to-buffer rmail-summary-buffer))
  871.  
  872. (defun rmail-summary-abort-edit ()
  873.   "Abort edit of current message; restore original contents.
  874. Go back to summary buffer."
  875.   (interactive)
  876.   (rmail-abort-edit)
  877.   (pop-to-buffer rmail-summary-buffer))
  878.  
  879. (defun rmail-summary-search-backward (regexp &optional n)
  880.   "Show message containing next match for REGEXP.
  881. Prefix argument gives repeat count; negative argument means search
  882. backwards (through earlier messages).
  883. Interactively, empty argument means use same regexp used last time."
  884.   (interactive
  885.     (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
  886.        (prompt
  887.         (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
  888.        regexp)
  889.       (if rmail-search-last-regexp
  890.       (setq prompt (concat prompt
  891.                    "(default "
  892.                    rmail-search-last-regexp
  893.                    ") ")))
  894.       (setq regexp (read-string prompt))
  895.       (cond ((not (equal regexp ""))
  896.          (setq rmail-search-last-regexp regexp))
  897.         ((not rmail-search-last-regexp)
  898.          (error "No previous Rmail search string")))
  899.       (list rmail-search-last-regexp
  900.         (prefix-numeric-value current-prefix-arg))))
  901.   ;; Don't use save-excursion because that prevents point from moving
  902.   ;; properly in the summary buffer.
  903.   (let ((buffer (current-buffer)))
  904.     (unwind-protect
  905.     (progn
  906.       (set-buffer rmail-buffer)
  907.       (rmail-search regexp (- n)))
  908.       (set-buffer buffer))))
  909.  
  910. (defun rmail-summary-search (regexp &optional n)
  911.   "Show message containing next match for REGEXP.
  912. Prefix argument gives repeat count; negative argument means search
  913. backwards (through earlier messages).
  914. Interactively, empty argument means use same regexp used last time."
  915.   (interactive
  916.     (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
  917.        (prompt
  918.         (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
  919.        regexp)
  920.       (if rmail-search-last-regexp
  921.       (setq prompt (concat prompt
  922.                    "(default "
  923.                    rmail-search-last-regexp
  924.                    ") ")))
  925.       (setq regexp (read-string prompt))
  926.       (cond ((not (equal regexp ""))
  927.          (setq rmail-search-last-regexp regexp))
  928.         ((not rmail-search-last-regexp)
  929.          (error "No previous Rmail search string")))
  930.       (list rmail-search-last-regexp
  931.         (prefix-numeric-value current-prefix-arg))))
  932.   ;; Don't use save-excursion because that prevents point from moving
  933.   ;; properly in the summary buffer.
  934.   (let ((buffer (current-buffer)))
  935.     (unwind-protect
  936.     (progn
  937.       (set-buffer rmail-buffer)
  938.       (rmail-search regexp n))
  939.       (set-buffer buffer))))
  940.  
  941. (defun rmail-summary-toggle-header ()
  942.   "Show original message header if pruned header currently shown, or vice versa."
  943.   (interactive)
  944.   (save-excursion
  945.     (set-buffer rmail-buffer)
  946.     (rmail-toggle-header)))
  947.  
  948. (defun rmail-summary-add-label (label)
  949.   "Add LABEL to labels associated with current Rmail message.
  950. Completion is performed over known labels when reading."
  951.   (interactive (list (save-excursion
  952.                (set-buffer rmail-buffer)
  953.                (rmail-read-label "Add label"))))
  954.   (save-excursion
  955.     (set-buffer rmail-buffer)
  956.     (rmail-add-label label)))
  957.  
  958. (defun rmail-summary-kill-label (label)
  959.   "Remove LABEL from labels associated with current Rmail message.
  960. Completion is performed over known labels when reading."
  961.   (interactive (list (save-excursion
  962.                (set-buffer rmail-buffer)
  963.                (rmail-read-label "Kill label"))))
  964.   (save-excursion
  965.     (set-buffer rmail-buffer)
  966.     (rmail-set-label label nil)))
  967.  
  968. ;;;; *** Rmail Summary Mailing Commands ***
  969.  
  970. (defun rmail-summary-mail ()
  971.   "Send mail in another window.
  972. While composing the message, use \\[mail-yank-original] to yank the
  973. original message into it."
  974.   (interactive)
  975.   (mail-other-window nil nil nil nil nil rmail-buffer)
  976.   (use-local-map (copy-keymap (current-local-map)))
  977.   (define-key (current-local-map)
  978.     "\C-c\C-c" 'rmail-summary-send-and-exit))
  979.  
  980. (defun rmail-summary-continue ()
  981.   "Continue composing outgoing message previously being composed."
  982.   (interactive)
  983.   (mail-other-window t))
  984.  
  985. (defun rmail-summary-reply (just-sender)
  986.   "Reply to the current message.
  987. Normally include CC: to all other recipients of original message;
  988. prefix argument means ignore them.
  989. While composing the reply, use \\[mail-yank-original] to yank the
  990. original message into it."
  991.   (interactive "P")
  992.   (let (mailbuf)
  993.     (save-window-excursion
  994.       (set-buffer rmail-buffer)
  995.       (rmail-reply just-sender)
  996.       (setq mailbuf (current-buffer)))
  997.     (pop-to-buffer mailbuf)
  998.     (use-local-map (copy-keymap (current-local-map)))
  999.     (define-key (current-local-map)
  1000.       "\C-c\C-c" 'rmail-summary-send-and-exit)))
  1001.  
  1002. (defun rmail-summary-retry-failure ()
  1003.   "Edit a mail message which is based on the contents of the current message.
  1004. For a message rejected by the mail system, extract the interesting headers and
  1005. the body of the original message; otherwise copy the current message."
  1006.   (interactive)
  1007.   (let (mailbuf)
  1008.     (save-window-excursion
  1009.       (set-buffer rmail-buffer)
  1010.       (rmail-retry-failure)
  1011.       (setq mailbuf (current-buffer)))
  1012.     (pop-to-buffer mailbuf)
  1013.     (use-local-map (copy-keymap (current-local-map)))
  1014.     (define-key (current-local-map)
  1015.       "\C-c\C-c" 'rmail-summary-send-and-exit)))
  1016.  
  1017. (defun rmail-summary-send-and-exit ()
  1018.   "Send mail reply and return to summary buffer."
  1019.   (interactive)
  1020.   (mail-send-and-exit t))
  1021.  
  1022. (defun rmail-summary-forward (resend)
  1023.   "Forward the current message to another user.
  1024. With prefix argument, \"resend\" the message instead of forwarding it;
  1025. see the documentation of `rmail-resend'."
  1026.   (interactive "P")
  1027.   (save-excursion
  1028.     (set-buffer rmail-buffer)
  1029.     (rmail-forward resend)
  1030.     (use-local-map (copy-keymap (current-local-map)))
  1031.     (define-key (current-local-map)
  1032.       "\C-c\C-c" 'rmail-summary-send-and-exit)))
  1033.  
  1034. ;; Summary output commands.
  1035.  
  1036. (defun rmail-summary-output-to-rmail-file ()
  1037.   "Append the current message to an Rmail file named FILE-NAME.
  1038. If the file does not exist, ask if it should be created.
  1039. If file is being visited, the message is appended to the Emacs
  1040. buffer visiting that file."
  1041.   (interactive)
  1042.   (save-excursion
  1043.     (set-buffer rmail-buffer)
  1044.     (call-interactively 'rmail-output-to-rmail-file)))
  1045.  
  1046. (defun rmail-summary-output ()
  1047.   "Append this message to Unix mail file named FILE-NAME."
  1048.   (interactive)
  1049.   (save-excursion
  1050.     (set-buffer rmail-buffer)
  1051.     (call-interactively 'rmail-output)))
  1052.  
  1053. ;; Sorting messages in Rmail Summary buffer.
  1054.  
  1055. (defun rmail-summary-sort-by-date (reverse)
  1056.   "Sort messages of current Rmail summary by date.
  1057. If prefix argument REVERSE is non-nil, sort them in reverse order."
  1058.   (interactive "P")
  1059.   (rmail-sort-from-summary (function rmail-sort-by-date) reverse))
  1060.  
  1061. (defun rmail-summary-sort-by-subject (reverse)
  1062.   "Sort messages of current Rmail summary by subject.
  1063. If prefix argument REVERSE is non-nil, sort them in reverse order."
  1064.   (interactive "P")
  1065.   (rmail-sort-from-summary (function rmail-sort-by-subject) reverse))
  1066.  
  1067. (defun rmail-summary-sort-by-author (reverse)
  1068.   "Sort messages of current Rmail summary by author.
  1069. If prefix argument REVERSE is non-nil, sort them in reverse order."
  1070.   (interactive "P")
  1071.   (rmail-sort-from-summary (function rmail-sort-by-author) reverse))
  1072.  
  1073. (defun rmail-summary-sort-by-recipient (reverse)
  1074.   "Sort messages of current Rmail summary by recipient.
  1075. If prefix argument REVERSE is non-nil, sort them in reverse order."
  1076.   (interactive "P")
  1077.   (rmail-sort-from-summary (function rmail-sort-by-recipient) reverse))
  1078.  
  1079. (defun rmail-summary-sort-by-correspondent (reverse)
  1080.   "Sort messages of current Rmail summary by other correspondent.
  1081. If prefix argument REVERSE is non-nil, sort them in reverse order."
  1082.   (interactive "P")
  1083.   (rmail-sort-from-summary (function rmail-sort-by-correspondent) reverse))
  1084.  
  1085. (defun rmail-summary-sort-by-lines (reverse)
  1086.   "Sort messages of current Rmail summary by lines of the message.
  1087. If prefix argument REVERSE is non-nil, sort them in reverse order."
  1088.   (interactive "P")
  1089.   (rmail-sort-from-summary (function rmail-sort-by-lines) reverse))
  1090.  
  1091. (defun rmail-sort-from-summary (sortfun reverse)
  1092.   "Sort Rmail messages from Summary buffer and update it after sorting."
  1093.   (require 'rmailsort)
  1094.   (pop-to-buffer rmail-buffer)
  1095.   (funcall sortfun reverse)
  1096.   (rmail-summary))
  1097.  
  1098. ;;; rmailsum.el ends here
  1099.